package com.ruoyi.app.service.impl;

import com.ruoyi.app.domain.MemberUser;
import com.ruoyi.app.domain.OperStaff;
import com.ruoyi.app.service.impl.mapper.MemberUserMapper;
import com.ruoyi.app.service.impl.mapper.OperStaffMapper;
import com.ruoyi.app.service.IMemberUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IMemberUserServiceImpl implements IMemberUserService {

    @Autowired
    private MemberUserMapper memberUserMapper;

    @Autowired
    private OperStaffMapper operStaffMapper;
    @Override
    public int checkLoginNameIsRegister(String loginName) {
        MemberUser memberUser = new MemberUser();
        memberUser.setUsername(loginName);
        List<MemberUser> list = memberUserMapper.selectMemberBaseList(memberUser);
        return list.size();
    }
    @Override
    public MemberUser checkEmailIsRegister(String email) {
        MemberUser memberUser = new MemberUser();
        memberUser.setEmail(email);
        List<MemberUser> list = memberUserMapper.selectMemberBaseList(memberUser);
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }

    @Override
    public OperStaff selectMemberBaseById(String id) {
        OperStaff operStaff = new OperStaff();
        operStaff.setId(Integer.parseInt(id));
        List<OperStaff> list = operStaffMapper.selectOperStaffList(operStaff);
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }

    @Override
    public MemberUser checkRecemIsExist(String recemCode) {
        MemberUser memberUser = new MemberUser();
        memberUser.setCodes(recemCode);
        List<MemberUser> list = memberUserMapper.selectMemberBaseList(memberUser);
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }

    }
    @Override
    public OperStaff checkLogin(String username) {
        OperStaff operStaff = new OperStaff();
        operStaff.setLoginName(username);

        List<OperStaff> list = operStaffMapper.selectOperStaffList(operStaff);
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }

    }
    @Override
    public int insertMemberUser(MemberUser memberUser) {

        int res = memberUserMapper.insertMemberUser(memberUser);
        return res;
    }

    @Override
    public int updateMemberUser(MemberUser memberUser) {

        int res = memberUserMapper.updateMemberUser(memberUser);
        return res;
    }
}
